<?php

class service_l_newsl8r {

    public function __construct() {
    }

    public function crealte_a_letter($name,$group_id,$description="",$content=""){
        $letter = new letter_m_newsl8r();
        $letter->name = $name;
        $letter->description = $description;
        $letter->group_id   = $group_id;
        $letter->content = $content;
        return $letter->save() ? $letter:NULl;
    }

    public function update_a_letter($id, $name,$group_id,$description="",$content=""){
        $letter = new letter_m_newsl8r();
        $letter->get_by_id($id);
        if($letter->exists()){
            $letter->name = $name;
            $letter->description = $description;
            $letter->group_id   = $group_id;
            $letter->content = $content;
            return $letter->save() ? $letter:NULl;
        }else{
            return NULL;
        }

    }

    public function delete_letter($letter_id){
        $letter = new letter_m_newsl8r();
        $letter->get_by_id($letter_id);
        if($letter->exists()){
            return $letter->delete() ? TRUE:FALSE;            
        }else{
            return NULL;
        }
    }

    public function get_letter_obj($id){
        return get_object($id, "letter_m_newsl8r");
    }

    public function get_all_letters($group_id=NULL){
        $letters = new letter_m_newsl8r();
        if($group_id!==NULL){
            $letters->get_by_group_id($group_id);
        }
        else{
            $letters->get();
        }
        if($letters->result_count()>0){
            return $letters;
        }else{
            return NULL;
        }
    }

}

?>
